﻿using BBICMS.Infrastructure;
using BBICMS.Infrastructure.Email;
using BBICMS.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace BBICMS.WebUI.Controllers.api
{
    public class SendEmailController : ApiController
    {
        [HttpPost]

        public HttpResponseMessage Post(SendEmail sendEmail)
        {
            try
            {


                SMTPService ss = new SMTPService();
                sendEmail.Body = string.Format("<p>{0}</p><p>发件人：{1} ({2}), 发件人邮箱：{3}</p>", sendEmail.Body, 
                    sendEmail.Name, sendEmail.Phone, sendEmail.Email);
               
                ss.SendMail(Helpers.Settings.ContactForm.MailTo, Helpers.Settings.ContactForm.MailCC, sendEmail.Subject, sendEmail.Body);
                

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, sendEmail);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = sendEmail.Email }));
                    return response;
              
              
            }
            catch (Exception ex)
            {
                return Request.
                    CreateErrorResponse(HttpStatusCode.BadRequest, ex);
            }
        }

    }
}
